package com.maze.game.factory
{
	import com.maze.app.AppText;
	import com.maze.game.model.base.Base;
	import com.maze.game.model.base.BaseExit;
	import com.maze.game.model.base.BasePoint;
	import com.maze.game.model.base.BaseStart;
	import com.maze.game.model.base.BaseType;
	import com.maze.game.model.base.NormalBase;

	public class BaseFactory
	{
		private var _baseWidth:uint;
		public function get baseWidth():uint { return _baseWidth; }
		public function set baseWidth(value:uint):void { _baseWidth = value; }

		private var _baseHeight:uint;
		public function get baseHeight():uint { return _baseHeight; }
		public function set baseHeight(value:uint):void { _baseHeight = value; }

		private static var _instance:BaseFactory = null;
		
		public function BaseFactory(enforcer:SingletonEnforcer)
		{
			if (_instance != null) { throw new Error(AppText.ERROR_SINGLETON_INSTANCE); }
		}

		public static function getInstance():BaseFactory
		{
			if(_instance == null)
			{
				_instance = new BaseFactory(new SingletonEnforcer());
			}
			return _instance;
		}

		private function getNormalWallBase():NormalBase
		{
			return new NormalBase(baseWidth,baseHeight, BaseType.WALL);
		}
		
		private function getNormalEmptyBase():NormalBase
		{
			return new NormalBase(baseWidth,baseHeight, BaseType.EMPTY);
		}
		
		private function getStartBase():BaseStart
		{
			return new BaseStart(baseWidth,baseHeight);
		}
		
		private function getExitBase():BaseExit
		{
			return new BaseExit(baseWidth,baseHeight);
		}
		
		public function getBase(type:uint):Base
		{
			var base:Base;
			switch(type)
			{
				case BaseType.EMPTY:
				{
					base = getNormalEmptyBase();
					break;
				}
					
				case BaseType.WALL:
				{
					base = getNormalWallBase();
					break;
				}

				case BaseType.START:
				{
					base = getStartBase();
					break;
				}
					
				case BaseType.EXIT:
				{
					base = getExitBase();
					break;
				}
					
				default:
				{
					base = getNormalEmptyBase();
					break;
				}
			}
			return base;
		}
		
		public function getWhitePoint():Base
		{
			return new BasePoint(baseWidth, baseHeight, 0xffffff);
		}

		public function getColorPoint(color:uint):Base
		{
			return new BasePoint(baseWidth, baseHeight, color);
		}
	}
}
class SingletonEnforcer {}